﻿using System;
using System.Collections.Generic;

namespace CrmClient.QueryConvert
{
    internal static class QueryConvertorFactory
    {
        private static Dictionary<Type, object> _convertors = new Dictionary<Type, object>();

        public static IQueryConvertor<T> GetConvertor<T>(PropertiesMap propertiesMap, string entityName)
        {
            var type = typeof(T);
            if (!_convertors.ContainsKey(type))
                if (propertiesMap == null)
                    _convertors.Add(type, new FastQueryConvertor<T>());
                else
                    _convertors.Add(type, new FastQueryConvertor<T>(propertiesMap, entityName));
            return (IQueryConvertor<T>)_convertors[type];
        }

        public static IQueryConvertor<T> GetConvertor<T>()
        {
            return GetConvertor<T>(null, null);
        }
    }
}
